package com.products.utils;

import java.util.List;
import javax.swing.JComboBox;
import com.products.model.Product;

public class ProductComboBox extends JComboBox {
	private static final long serialVersionUID = 1L;
	private List<Product> products = null;
	
	public void setItems(List<Product> products){
		this.removeAllItems();
		this.products = products;
		for (int i=0; i<products.size(); i++){
			Product product = products.get(i);
			this.addItem(product.getProductName());
		}
	}
	
	public Product getProduct(){
		int index = this.getSelectedIndex();
		System.out.println("index="+index);
		return products.get(index);
	}
}
